package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    //规则: 遇到某种异常时 执行该方法 返回特定的数据
    @ExceptionHandler(RuntimeException.class)
    public Result fail(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    public Result resultCode(LeaseException leaseException){

        return Result.build(null,leaseException.getResultCodeEnum());
    }
}
